package com.lichao.FinkDataProcess.codehaus;

import org.codehaus.janino.SimpleCompiler;

public class JaninoTest {
    public static void main(String[] args) throws Exception {
//        System.out.println("hello");
        // 类定义
        String classDef = "public class HelloWorld {\n" +
                "    public static void helloWorld(){\n" +
                "        System.out.println(\"hello\");\n" +
                "    }\n" +
                "}";

        // 使用janino动态编译字符串并加载进类加载器
        SimpleCompiler sc = new SimpleCompiler();
        sc.cook(classDef);
        Class<?> clazz = sc.getClassLoader().loadClass("HelloWorld");

        // 使用janino执行
        clazz.getMethod("helloWorld").invoke(null);
    }
}
